package com.surekam.service;

import java.io.IOException;
import java.sql.Date;
import java.util.List;

import org.ksoap2.SoapEnvelope;
import org.ksoap2.serialization.PropertyInfo;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.HttpTransportSE;
import org.xmlpull.v1.XmlPullParserException;

import android.content.Context;

public class ServiceImpl implements IService {
    private Context context;
    String NAMESPACE = "http://tempuri.org/";
    String SERVICE_URL="http://erp.surekam.com/webservice/EpmService/ContactService.svc";
    String validateMethod="AuthenticateUser";	
    String getContactsMethod="GetContacts";
    String soapAction1="http://tempuri.org/IContactService/AuthenticateUser";
    String soapAction2="http://tempuri.org/IContactService/GetContacts";

    protected ServiceImpl(Context context) {
	this.context = context;
    }

  
    public String validate(String userName, String passwd) {
	String returnResult = "netError";
	try {
    	SoapObject soapObject = new SoapObject(NAMESPACE,validateMethod);
    	
    	PropertyInfo info = new PropertyInfo();
    	info.name = "userId";
    	PropertyInfo info2 = new PropertyInfo();
    	info2.name = "password";
    	
    	soapObject.addProperty(info, userName);
    	soapObject.addProperty(info2, passwd);
    	
    	SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
    	envelope.bodyOut = soapObject;
    	envelope.dotNet = true;
    	
    	
    	HttpTransportSE ht = new HttpTransportSE(SERVICE_URL);
	
	ht.call(soapAction1, envelope);
	
	String result = envelope.getResponse().toString();
	
	if(Boolean.parseBoolean(result)){
	    returnResult = "true";
	}else {
	    returnResult = "false";
	}
	
	} catch (Exception e) {
	    e.printStackTrace();
	}
	return returnResult;
    }

 
    public List getContacts(Date date) {
	// TODO Auto-generated method stub
	return null;
    }

}
